﻿using System.Collections;
using System.Collections.Generic;

using Dict.DataModel;
namespace Dict.Blo
{
    public class DictHeroExpBlo
    {
        public static int GetHeroLevelExp(int quality,int level)
        {
            if (level <= 1)
                return 0;
            List<TableHeroExp> list = Dict.DictDataManager.Instance.tableHeroExpDao.GetByOneIndex(quality);
            return list[level - 2].exp;
        }

        public static int GetHeroMaxLevel(int quality)
        {
            List<TableHeroExp> list = Dict.DictDataManager.Instance.tableHeroExpDao.GetByOneIndex(quality);
            return list.Count;
        }

        public static long GetHeroExpToLevel(int quality, int level)
        {
            if (level <= 1)
                return 0;
            List<TableHeroExp> list = Dict.DictDataManager.Instance.tableHeroExpDao.GetByOneIndex(quality);
            long exp = 0;
            for(int i = 0; i < list.Count; i++)
            {
                if(i <= level - 2)
                {
                    exp += list[i].exp;
                }
            }

            return exp;
        }
        
        public static int GetPredictLevelWithExp(int quality, int curLevel, long exp)
        {
            List<TableHeroExp> list = Dict.DictDataManager.Instance.tableHeroExpDao.GetByOneIndex(quality);
            long totalExp = exp;
            int predictlv = curLevel;
            for (int i = curLevel - 1; i < list.Count; i++)
            {
                if (totalExp > list[i].exp && list[i].exp > 0)
                {
                    totalExp -= list[i].exp;
                    predictlv = i + 2;
                }
                else
                {
                    break;
                }
            }

            return predictlv;
        }
    }

}
